#include<iostream>
#include<cstring>
using namespace std;
class CBook
{
    private:
        string BookName,tutor,place;
        double money;
    public:
        CBook(string bn="",string tu="",string pl="",double mo=0)
        {
            BookName=bn;
            tutor=tu;
            place=pl;
            money=mo;
        }
        friend istream& operator>>(istream& is,CBook& tmp)
        {
            is>>tmp.BookName>>tmp.tutor>>tmp.money>>tmp.place;
            return is;
        }
        friend ostream& operator<<(ostream& os,CBook& tmp)
        {
            os<<tmp.BookName<<endl;
            os<<tmp.tutor<<endl;
            printf("%.2f\n",tmp.money);
            os<<tmp.place<<endl;
        }
        friend void find(CBook *book, int n, int &max1index,int &max2index);
};
void find(CBook *book, int n, int &max1index,int &max2index)
{
    max1index=book[0].money>book[1].money?0:1;
    max2index=max1index==0?1:0;
    for(int i=2;i<n;++i)
    {
        if(book[i].money>book[max1index].money)
        {
            max2index=max1index;
            max1index=i;
        }
        else if(book[i].money>book[max2index].money)
        {
            max2index=i;
        }
    }
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        CBook *num=new CBook[n];
        for(int i=0;i<n;++i)
        {
            cin>>num[i];
        }
        int max1,max2;
        find(num,n,max1,max2);
        cout<<num[max1]<<endl;
        cout<<num[max2];
        delete[] num;
    }
}